package com.young.common.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: yangwei
 * @Date: 2018/9/11 0011 13:35
 * @Description: 请求状态
 */
public enum DataStatus {
    /**
     * The success.
     *
     * 200,"success"
     */
    SUCCESS(200,"success"),

    /**
     * 404,"no data"
     */
    NO_DATA(404,"no data"),

    /**
     *
     * 500,"server error"
     *
     */
    ERROR(500,"server error"),

    /**
     * 601,"Request parameter exception"
     */
    REQUEST_PARAMETER_EXCEPTION(601,"Request parameter exception"),

    /**
     * The unknown.
     *
     * 999,"unknown"
     */
    UNKNOWN(999,"unknown");

    /**
     * 代码
     */
    private Integer code;

    /**
     * 描述
     */
    private String msg;


    private DataStatus (Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * The Constant responseCodeMap.
     */
    private final static Map<Integer, DataStatus> responseCodeMap = new HashMap<Integer, DataStatus>();

    static {
        for (DataStatus code : DataStatus.values() ) {
            responseCodeMap.put(code.getCode(), code );
        }
    }

    public static DataStatus findCode(Integer code){
        DataStatus ecode = responseCodeMap.get(code);

        if (ecode==null) {
            ecode = UNKNOWN;
        }
        return ecode;
    }


    public static Map<Integer, DataStatus> findCodeMap () {
        return responseCodeMap;
    }

    /**
     * Gets the 代码.
     *
     * @return the 代码
     */
    public Integer getCode() {
        return code;
    }

    /**
     * Sets the 代码.
     *
     * @param code
     *            the new 代码
     */
    public void setCode(Integer code) {
        this.code = code;
    }

    /**
     * Gets the 描述.
     *
     * @return the 描述
     */
    public String getMsg() {
        return msg;
    }

    /**
     * Sets the 描述.
     *
     * @param msg
     *            the new 描述
     */
    public void setMsg(String msg) {
        this.msg = msg;
    }

}
